package com.iwuke.dance.util;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;

import java.util.ArrayList;
import java.util.List;

import androidx.core.app.ActivityCompat;

/**
 * @author: 魏从响
 * @date: 2025/10/15
 */
public class RequestPermissions {

    public static final int REQ_PERMISSION_CODE = 0x0010;
    /**
     * @description 拍照权限和访问图片权限
     * @param
     */
    public static boolean checkPermissionCamera(Context context) {
        try {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                List<String> permissions = new ArrayList<>();
                //拍照权限
                if (PackageManager.PERMISSION_GRANTED != ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA)) {
                    permissions.add(Manifest.permission.CAMERA);
                }

                //READ_EXTERNAL_STORAGE  读取外部存储器  访问图片权限
                if (PackageManager.PERMISSION_GRANTED != ActivityCompat.checkSelfPermission(context,Manifest.permission.READ_EXTERNAL_STORAGE)) {
                    permissions.add(Manifest.permission.READ_EXTERNAL_STORAGE);
                }

                if (permissions.size() != 0) {
                    ActivityCompat.requestPermissions((Activity) context,permissions.toArray(new String[0]), REQ_PERMISSION_CODE);
                    return false;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }

}
